package com.ocm.tourism.core.jdbc.rowmapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;

import com.ocm.tourism.core.domain.FileInfo;
import com.ocm.tourism.core.domain.Hotel;
import com.ocm.tourism.core.domain.SaleOff;

public class HotelRowMapper implements RowMapper<Hotel>{

   public Hotel mapRow(ResultSet resultSet, int rownumber) throws SQLException {
      Hotel hotel = new Hotel();
      hotel.setId(resultSet.getLong("b_id"));
      hotel.setAddress(resultSet.getString("b_address"));
      hotel.setDescription(resultSet.getString("bus_desc"));
      hotel.setFax(resultSet.getString("bus_fax"));
      hotel.setMobilephone(resultSet.getString("bus_mobile"));
      hotel.setHomephone(resultSet.getString("bus_homephone"));
      hotel.setName(resultSet.getString("bus_name"));

      FileInfo avatar = new FileInfo();
      avatar.setId(resultSet.getLong("fi_id"));
      avatar.setAbsolutePath(resultSet.getString("fi_absolutepath"));
      avatar.setExtension(resultSet.getString("fi_extension"));
      avatar.setFileDetail(resultSet.getString("fi_fileDetail"));
      avatar.setMimetypes(resultSet.getString("fi_minetypes"));
      avatar.setName(resultSet.getString("fi_name"));

      SaleOff saleOff = new SaleOff();
      saleOff.setId(resultSet.getLong("a_id"));
      saleOff.setContent(resultSet.getString("a_title"));
      saleOff.setTitle(resultSet.getString("a_content"));

      hotel.setAvatar(avatar);
      List<SaleOff> saleoffs = new ArrayList<SaleOff>();
      saleoffs.add(saleOff);
      hotel.setSaleOffs(saleoffs);
      return hotel;
   }
}
